//
//  MainTabBarController.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/6/28.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "MainTabBarController.h"
#import "HomeViewController.h"
#import "OptionalViewController.h"
#import "ActivityViewController.h"
#import "MySelfViewController.h"
#import "BlackNavViewController.h"


#define kUITabBarHeight 49
#define kTabBarItemCount 4

@interface MainTabBarController () <UITabBarControllerDelegate>

// 自定义的 TabBar
@property (nonatomic, strong) UIView *mlTabBar;

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}


-(void)setupUI {
    
    [[UITabBar appearance] setBarTintColor:ColorWithRGB(0x242424)];
    
    [UITabBar appearance].translucent = NO;
    
    HomeViewController * homeVC = [HomeViewController new];
    homeVC.title = @"交易";

    OptionalViewController * optionalVC = [OptionalViewController new];
    optionalVC.title = @"自选";
    
    ActivityViewController * activityVC = [ActivityViewController new];
    activityVC.title = @"活动";
    
    MySelfViewController * myVC = [MySelfViewController new];
    myVC.title = @"我的";
    
    BlackNavViewController * homeNav = [[BlackNavViewController alloc] initWithRootViewController:homeVC];
    
    BlackNavViewController * optionalNav = [[BlackNavViewController alloc] initWithRootViewController:optionalVC];
    
    BlackNavViewController * activityNav = [[BlackNavViewController alloc] initWithRootViewController:activityVC];
    
    BlackNavViewController * maselfNav = [[BlackNavViewController alloc] initWithRootViewController:myVC];
    
    
    //设置控制器图片(使用imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal,不被系统渲染成蓝色)
    homeNav.tabBarItem.image = [[UIImage imageNamed:@"交易默认"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    homeNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"交易点击"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    optionalNav.tabBarItem.image = [[UIImage imageNamed:@"自选默认"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    optionalNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"自选点击"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    activityNav.tabBarItem.image = [[UIImage imageNamed:@"活动默认"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    activityNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"活动点击"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    maselfNav.tabBarItem.image = [[UIImage imageNamed:@"我的默认"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    maselfNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"我的点击"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    //改变tabbarController 文字选中颜色(默认渲染为蓝色)
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];
    
    //创建一个数组包含四个导航栏控制器
    NSArray *vcArry = [NSArray arrayWithObjects:homeNav,optionalNav,activityNav,maselfNav,nil];
    
    //将数组传给UITabBarController
    self.viewControllers = vcArry;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
